#include "ObstacleFactory.h"

ObstacleFactory::ObstacleFactory(void)
{
}

ObstacleFactory::~ObstacleFactory(void)
{
}

Element * ObstacleFactory::createElement( XMLElement * element) {
	return this->createTriangleObstacle(element);
}

TriangularObstacle * ObstacleFactory::createTriangleObstacle(XMLElement* triangleElement) {
	TriangularObstacle * obstacle = NULL;
	Position * arrVertices[3];

	if(triangleElement->getName()->compare("triangulo") == 0) {
		list<XMLElement*> vertices = triangleElement->getElementsByName("vertice");
		list<XMLElement*>::iterator iterVertices;

		int i=0;
		for (iterVertices = vertices.begin();iterVertices != vertices.end(); iterVertices++) {
			XMLElement * verticeElement = *iterVertices;
			Position * vertice = FactoryUtil::getInstance()->buildPosition(verticeElement);
			arrVertices[i++] = vertice;
		}
		obstacle = new TriangularObstacle(arrVertices[0],arrVertices[1],arrVertices[2]);
	}
	return obstacle;
}